//
//  Person.m
//  05-排序、数组字典的处理
//
//  Created by LL.F on 16/7/8.
//  Copyright © 2016年 LL.F. All rights reserved.
//

#import "Person.h"

@implementation Person

// 初始化
- (instancetype)initWithName:(NSString *)name age:(NSInteger)age gender:(NSString *)gender
{

    self = [super init];
    if (self) {
        _name = name;
        _age = age;
        _gender = gender;
    }
    return self;
}
// 构造器
+ (instancetype)personWithName:(NSString *)name age:(NSInteger)age gender:(NSString *)gender
{

    return [[Person alloc] initWithName:name age:age gender:gender];

}

- (NSString *)description
{

    return [NSString stringWithFormat:@"%@--%ld--%@", _name, _age, _gender];
}
// 按年龄排序
- (NSComparisonResult)compareByAge:(Person *)anotherPerson
{

    return [[NSNumber numberWithInt:(int)self.age] compare:[NSNumber numberWithInt:(int)anotherPerson.age]];
}

// 按姓名排序
- (NSComparisonResult)compareByName:(Person *)anotherPerson
{

    return [self.name compare:anotherPerson.name];
}
// 按性别排序
- (NSComparisonResult)compareByGender:(Person *)anotherPerson
{
    
    return [self.gender compare:anotherPerson.gender];
}
@end
